# coding:utf-8
"""
这里AppiumTest文件
"""

"""
标准库导入
"""
import os, time
import unittest

"""
三方库导入
"""
from appium import webdriver

"""
自定义库导入
"""

"""
主体方法
"""
PATH = lambda p: os.path.abspath(
    os.path.join(os.path.dirname(__file__), p)
)


class Test(unittest.TestCase):
    def setUp(self) -> None:
        desired_caps = {
            "platformName": "Android",
            "platformVersion": "10.0",
            "deviceName": "YAL-AL00",
            "newCommandTimeout": 240,
            "udid": "CUY0219528010121",
            "appActivity": "io.dcloud.PandoraEntry",
            "appPackage": "com.yemaogj.bar"
        }
        self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

    def test(self):
        driver = self.driver
        el1 = driver.find_element_by_xpath("(//android.widget.TextView[@content-desc=\"夜猫吧台\"])[1]")
        el1.click()
        el2 = driver.find_element_by_xpath(
            "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[2]/android.view.View/android.widget.EditText")
        el2.send_keys("funtest01")
        el3 = driver.find_element_by_xpath(
            "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[3]/android.view.View/android.widget.EditText")
        el3.send_keys("123123")
        el4 = driver.find_element_by_xpath(
            "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[4]")
        el4.click()

        time.sleep(5)

    def tearDown(self) -> None:
        self.driver.quit()


# 程序入口
if __name__ == '__main__':
    unittest.main()
